package com.ef.web.action;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;

import com.ef.constant.ConfirmMessage;
import com.ef.domain.Gift;
import com.ef.service.GiftService;
import com.ef.util.CustomExample;

public class GiftAction extends BaseAction<Gift> {

	private static final long serialVersionUID = 1L;
	private GiftService giftService;

	protected final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
			.getLog(GiftAction.class);

	@SuppressWarnings("serial")
	public String list() {

		this.listResult = giftService.findByExample(new CustomExample<Gift>(
				this.getModel()) {

			public void appendCondition(Criteria criteria) {
				this.enableLike(MatchMode.ANYWHERE);
			}
		}, this.getStartIndex(), this.getPageSize());
		return LIST;
	}

	public String edit() {

		return EDIT;
	}

	public String save() {

		Gift gift = this.getModel();
		gift.setUpdateTime(new Date());
		gift.setUpdateUser(getSessionUser());
		giftService.saveOrUpdate(gift);
		this.setResult(ConfirmMessage.Gift);
		return EDIT;
	}

	public String delete() {
		String ids = getRequest().getParameter("ids");
		String[] id = ids.split(",");
		for (String i : id) {
			giftService.delete(giftService.findById(Long.valueOf(i)));
		}

		return DELETE;
	}

	public GiftService getGiftService() {
		return giftService;
	}

	public void setGiftService(GiftService giftService) {
		this.giftService = giftService;
	}

}
